<template>
  <el-container>
    <!-- aside -->
    <el-aside width="200">
      <h1 class="logo"></h1>
      <el-menu
        class="el-qf-menu"
        :collapse="collapse"
        :default-active="$route.path"
      >
        <qf-sub-menu :sideMenu="sideMenu"></qf-sub-menu>
      </el-menu>
    </el-aside>

    <el-container>
      <!-- header -->
      <el-header>
        <el-row type="flex" class="row-bg" justify="space-between">
          <el-col :span="6"
            ><div class="grid-content left">
              <i
                @click="collapse = !collapse"
                :class="[
                  'iconfont',
                  collapse ? 'icon-zhankaicaidan' : 'icon-shouqi',
                ]"
              ></i></div
          ></el-col>
          <el-col :span="6"
            ><div class="grid-content center">CRM系统</div></el-col
          >
          <el-col :span="6"
            ><div class="grid-content right">
              <el-avatar
                shape="square"
                size="large"
                :src="avatarUrl"
              ></el-avatar>
              <b
                >欢迎您:<span class="nickname">{{ userInfo.nickname }}</span></b
              >
              &nbsp;
              <b @click="quit" class="quit">退出</b>
            </div></el-col
          >
        </el-row>
      </el-header>

      <!-- main -->
      <el-main>
        <!-- 面包屑 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item
            :to="{ name: bread.name }"
            v-for="bread in breadCrumb"
            :key="bread.name"
            >{{ bread.meta.name }}</el-breadcrumb-item
          >
        </el-breadcrumb>
        <router-view></router-view >
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState(["userInfo", "sideMenu", "breadCrumb"]),
    avatarUrl() {
      //如果没有头像使用默认头像，如果有使用用户头像
      return this.userInfo.headimgurl
        ? this.userInfo.headimgurl
        : "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png";
    },
  },
  mounted() {},
  data() {
    return {
      collapse: false,
    };
  },
  methods: {
    sendFn() {
      this.$store.dispatch("GET_MENULIST");
    },
    cancel() {
      this.cancelToken();
    },
    quit() {
      //1.清除token
      //2.跳转到登录页
      localStorage.removeItem("qf-token");
      this.$router.push("/login");
      //3.刷新页面
      location.reload();
    },
  },
};
</script>
<style scoped lang="less">
.el-header {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  color: #fff;
  font-weight: bold;
  text-align: center;
  //   line-height: 60px;
  min-height: 60px !important;
  line-height: 40px;
  .left {
    text-align: left;
    i {
      font-size: 30px;
      cursor: pointer;
    }
  }
  .center {
    font-size: 30px;
  }
  .el-avatar {
    vertical-align: middle;
    margin-right: 10px;
  }
  .quit {
    color: red;
    text-decoration: underline;
    cursor: pointer;
  }
  .nickname {
    margin-left: 5px;
    color: deepskyblue;
  }
}

.el-aside {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  color: #333;
  text-align: center;
  //   line-height: 200px;
  .logo {
    min-height: 60px;
  }
  .subMenu {
    text-align: left;
  }
  .el-qf-menu:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
}

.el-main {
  background-color: #fff;
  color: #333;
  text-align: center;
  //   line-height: 160px;
}

.el-container {
  margin-bottom: 40px;
  height: 100%;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}

.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}

.row-bg {
  padding: 10px 0;
}
</style>
